#!/bin/bash -e

######################
PASSWDFILE=/etc/passwd
GROUPFILE=/etc/group

frruid=`egrep "^frr:" $PASSWDFILE | awk -F ":" '{ print $3 }'`
frrgid=`egrep "^frr:" $GROUPFILE | awk -F ":" '{ print $3 }'`
frrvtygid=`egrep "^frrvty:" $GROUPFILE | awk -F ":" '{ print $3 }'`

[ -n ${frruid} ]    || (echo "No uid for frr in ${PASSWDFILE}"   && /bin/false)
[ -n ${frrgid} ]    || (echo "No gid for frr in ${GROUPFILE}"    && /bin/false)
[ -n ${frrVTYgid} ] || (echo "No gid for frrvty in ${GROUPFILE}" && /bin/false)

chown ${frruid}:${frrgid} /etc/frr
chown ${frruid}:${frrgid} /etc/frr/*
touch /etc/frr/vtysh.conf
chgrp ${frrvtygid} /etc/frr/vtysh*
chmod 644 /etc/frr/*

ENVIRONMENTFILE=/etc/environment
if ! grep --quiet VTYSH_PAGER=/bin/cat ${ENVIRONMENTFILE}; then
    echo "VTYSH_PAGER=/bin/cat"  >> ${ENVIRONMENTFILE}
fi
##################################################

if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*"}

# This is most likely due to the answer "no" to the "really stop the server"
# question in the prerm script.
if [ "$1" = "abort-upgrade" ]; then
  exit 0
fi

#DEBHELPER#

